export function getValueByPath(obj, path) {
  path = !Array.isArray(path) ? path.split('.') : path
  return path.reduce((ret, key) => ret[key], obj)
}

export function setValueByPath(obj, path, value) {
  path = !Array.isArray(path) ? path.split('.') : path
  let list = path.reduce(
    (list, key, index) => {
      if (index === path.length - 1) {
        list[index][key] = value
      } else {
        let target = list[index][key]
        if (Array.isArray(target)) {
          target = target.concat()
        } else {
          target = {...target}
        }
        list[index][key] = target
        list.push(target)
      }
      return list
    },
    [{ ...obj }]
  )
  return list[0]
}